﻿Imports DevComponents.DotNetBar
Imports quanlydulich.Helpers

Public Class TIMKIEMTOUR
    Inherits Office2007Form

    ' Event handler is used to transfer data to receiver
    Public Event Handler(ByVal sender As Object, ByVal e As MyEvent)

    Private Sub btnCapNhat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCapNhat.Click
        Close()
        RaiseEvent Handler(Me, New MyEvent(txtMaTour.Text & "#" & txtTenTour.Text & "#" & txtGiaTu.Text.Replace(",", "") & "#" & txtGiaDen.Text.Replace(",", "") & "#" & String.Format("{0:dd/MM/yyyy HH:mm:ss}", dtNgayBD.Value) & "#" & String.Format("{0:dd/MM/yyyy HH:mm:ss}", dtNgayKT.Value)))
    End Sub

    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        Close()
    End Sub

    Private Sub txtGiaTu_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtGiaTu.KeyPress
        ' Only allow type number
        If Not Char.IsNumber(e.KeyChar) And e.KeyChar <> Chr(Keys.Back) Then
            e.Handled = True
        End If
    End Sub

    ' This variable is used to end changing on textbox
    Private endChange As Boolean = False
    Private Sub txtGiaTu_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtGiaTu.TextChanged
        If endChange Then
            endChange = False
            Me.txtGiaTu.SelectionStart = Me.txtGiaTu.Text.Length
            Return
        End If
        If txtGiaTu.Text.Length > 0 Then
            Dim strOrigin = txtGiaTu.Text.Replace(",", "")
            Dim strFormated = String.Format("{0:#,##0;Nothing}", Long.Parse(strOrigin))
            If strOrigin <> strFormated Then
                endChange = True
                Me.txtGiaTu.Text = strFormated
            End If
        End If
    End Sub

    Private Sub txtGiaDen_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtGiaDen.KeyPress
        ' Only allow type number
        If Not Char.IsNumber(e.KeyChar) And e.KeyChar <> Chr(Keys.Back) Then
            e.Handled = True
        End If
    End Sub

    Private Sub txtGiaDen_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtGiaDen.TextChanged
        If endChange Then
            endChange = False
            Me.txtGiaDen.SelectionStart = Me.txtGiaDen.Text.Length
            Return
        End If
        If txtGiaDen.Text.Length > 0 Then
            Dim strOrigin = txtGiaDen.Text.Replace(",", "")
            Dim strFormated = String.Format("{0:#,##0;Nothing}", Long.Parse(strOrigin))
            If strOrigin <> strFormated Then
                endChange = True
                Me.txtGiaDen.Text = strFormated
            End If
        End If
    End Sub

    Private Sub btnCapNhat_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub
End Class